package pos.data;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import pos.domain.Deportista;
import pos.domain.Usuario;

public class JDBCDeportistaDAO implements IDeportistaDAO{	
	private IUsuarioDAO udao;
	private Connection conn;
	
	public JDBCDeportistaDAO()
	{
		conn = ConnectionManager.getInstance().checkOut();
		udao = new JDBCUsuarioDAO(conn);
	}
	public JDBCDeportistaDAO(Connection conn)
	{
		this.conn=conn;
		udao = new JDBCUsuarioDAO(conn);
	}
	public Deportista selectDeportista (String userName){
		return null;
	}
	public Deportista selectDeportistaByOID( String usuarioOID){
		PreparedStatement stmt = null;
		ResultSet result = null;
		Deportista u = null;
		String sql = "SELECT * FROM deportistas WHERE (OID = ?)";
		
		try{
			stmt = conn.prepareStatement(sql);
			stmt.setString(1, usuarioOID);
			result = stmt.executeQuery();
			
			result.next();
			u = new Deportista();
			u.setNombre(result.getString("nombre"));
			u.setApellidos(result.getString("apellidos"));
		
		} catch (SQLException e){
			System.out.println ("Message" + e.getMessage());
			System.out.println ("SQLState: " + e.getSQLState());
			System.out.println ("ErrorCode: " + e.getErrorCode());
		}finally {
			try{
				if (result != null){
					result.close();
				}
				if (stmt != null){
					stmt.close();
				}
			}catch (SQLException e){
			}
		}
		return u;
	}
	
	
}
